//
//  PayTipView.swift
//  旅航ios
//
//  Created by tulip on 2021/5/8.
//

import UIKit
import SwiftyJSON
import TangramKit

class PayTipView: UIView {
    var scrollview:UIScrollView!
    var tgview:TGLinearLayout!
    var tkData:JSON?
    var pgData:Array<Dictionary<String,Any>>?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor=UIColor.black.withAlphaComponent(0.6)
        
        let box=UIView.init(frame: CGRect(x: 20, y: SCREEN_HEIGHT/2.0-190, width: SCREEN_WIDTH-40, height: 380))
        box.backgroundColor=UIColor.white
        self.addSubview(box)
        
        let tip =  UILabel.init(frame: CGRect(x: 0, y: 15, width: SCREEN_WIDTH-40, height: 20))
        tip.text="付款后信息无法更改，请仔细核对以下信息"
        tip.textAlignment = .center
        tip.font=UIFont.systemFont(ofSize: 15)
        tip.textColor=UIColor.black
        box.addSubview(tip)
        
        scrollview=UIScrollView.init(frame: CGRect(x: 0, y: 50, width: SCREEN_WIDTH-40, height: 310))
        box.addSubview(scrollview)
        
        tgview=TGLinearLayout.init(.vert)
        scrollview.addSubview(tgview)
        tgview.tg_top.equal(0)
        tgview.tg_left.equal(0)
        tgview.tg_width.equal(SCREEN_WIDTH-40)
        tgview.tg_height.equal(.wrap)
        
        
    }
    
    
    func setUI(){
        
        let lineView1=UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 13))
        lineView1.tg_top.equal(10)
        lineView1.tg_left.equal(0)
        lineView1.tg_width.equal(SCREEN_WIDTH-40)
        lineView1.tg_height.equal(13)
        tgview.addSubview(lineView1)
        
        let xingcheng=UILabel.init(frame: CGRect(x: (SCREEN_WIDTH-40)/2.0-15, y: 0, width: 30, height: 13))
        xingcheng.text="行程"
        xingcheng.textColor=UIColor.init(hexString: "999999")
        xingcheng.font=UIFont.systemFont(ofSize: 14)
        xingcheng.textAlignment = .center
        lineView1.addSubview(xingcheng)
        
        let line1_left=UIView.init(frame: CGRect(x: 12, y: 6, width: (SCREEN_WIDTH-40)/2.0-12-28, height: 1))
        line1_left.backgroundColor=UIColor.init(hexString: "ebebeb")
        lineView1.addSubview(line1_left)
        
        let line1_right=UIView.init(frame: CGRect(x: (SCREEN_WIDTH-40)/2.0+28, y: 6, width: (SCREEN_WIDTH-40)/2.0-12-28, height: 1))
        line1_right.backgroundColor=UIColor.init(hexString: "ebebeb")
       lineView1.addSubview(line1_right)
        
        
        
        
        let  tk_cell=TipcellView.init(frame: CGRect(x: 0, y: 0, width: (SCREEN_WIDTH-40), height: 60))
        tgview.addSubview(tk_cell)
        tk_cell.tg_top.equal(20)
        tk_cell.tg_left.equal(0)
        tk_cell.tg_width.equal(SCREEN_WIDTH-40)
        tk_cell.tg_height.equal(60)
        tk_cell.tkData=self.tkData
        tk_cell.setText_json()
        
        
        
        let lineView2=UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 13))
        lineView2.tg_top.equal(10)
        lineView2.tg_left.equal(0)
        lineView2.tg_width.equal(SCREEN_WIDTH-40)
        lineView2.tg_height.equal(13)
        tgview.addSubview(lineView2)
        
        let passager=UILabel.init(frame: CGRect(x: (SCREEN_WIDTH-40)/2.0-25, y: 0, width: 50, height: 13))
        passager.text="乘机人"
        passager.textColor=UIColor.init(hexString: "999999")
        passager.font=UIFont.systemFont(ofSize: 14)
        passager.textAlignment = .center
        lineView2.addSubview(passager)
        
        let line2_left=UIView.init(frame: CGRect(x: 12, y: 6, width: (SCREEN_WIDTH-40)/2.0-12-28, height: 1))
        line2_left.backgroundColor=UIColor.init(hexString: "ebebeb")
        lineView2.addSubview(line2_left)
        
        let line2_right=UIView.init(frame: CGRect(x: (SCREEN_WIDTH-40)/2.0+28, y: 6, width: (SCREEN_WIDTH-40)/2.0-12-28, height: 1))
        line2_right.backgroundColor=UIColor.init(hexString: "ebebeb")
       lineView2.addSubview(line2_right)
        
        
        for i in 0 ..< pgData!.count   {
            let pg_cell=TipcellView.init(frame: CGRect(x: 0, y:20, width: SCREEN_WIDTH-40, height: 60))
            tgview.addSubview(pg_cell)
            pg_cell.tg_top.equal(20)
            pg_cell.tg_left.equal(0)
            pg_cell.tg_width.equal(SCREEN_WIDTH-40)
            pg_cell.tg_height.equal(60)
            pg_cell.pgDic=pgData?[i]  ?? ["name":"","idNum":""]
            pg_cell.setText_Dic()
        }
        
        
    
        let line3=UIView.init(frame: CGRect(x: 12, y: 0, width: (SCREEN_WIDTH-40)-24, height: 1))
        tgview.addSubview(line3)
        line3.tg_top.equal(15)
        line3.tg_left.equal(12)
        line3.tg_width.equal((SCREEN_WIDTH-40)-24)
        line3.tg_height.equal(1)
        line3.backgroundColor=UIColor.init(hexString: "ebebeb")
        
        scrollview.contentSize=CGSize(width: SCREEN_WIDTH-40, height: tgview.frame.size.height)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
